package ccnu.agile.config.resthelp;

import ccnu.agile.bean.request.Request;
import ccnu.agile.constant.System;
import ccnu.agile.utils.LogUtils;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description: Request请求体封装类
 * @Author: JreamY
 * @Date: 2021/11/4
 **/
@Configuration
public class RequestConcurrent {

    @Value("${custom.concurrent.max-request-size}")
    private Integer maxRequestSize=128;

    private Map<String, Request> container;

    {
        container = new HashMap<>(maxRequestSize);
    }

    public void log() {
        LogUtils.info(this, "requestConcurrent load complete");
    }

    public Request getCurrentRequest() {
        return container.get(MDC.get(System.MDC.TRANSACTION_ID));
    }

    public void putCurrentRequest(Request request) {
        container.put(MDC.get(System.MDC.TRANSACTION_ID), request);
    }

    public void removeCurrentRequest() {
        container.remove(MDC.get(System.MDC.TRANSACTION_ID));
    }

}
